package com.jquest.editor.components;

import com.l2fprod.common.propertysheet.*;

import javax.swing.*;
import java.awt.*;

/**
 * Created by IntelliJ IDEA.
 * User: Johan
 * Date: 2009-dec-19
 * Time: 13:43:28
 * To change this template use File | Settings | File Templates.
 */
public class PropertySidePanel extends JPanel {
    //ToDo: Code cleanup, bind these visual components to the editor itself, fix UI to allow smooth resizing
    PropertySheetTable pst;
    PropertySheetPanel psp;
    PropertySheetTableModel model;

    JPanel entityPanel;
    JList entityList;
    JScrollPane entityScroll;

    JLabel label1;

    JButton addEntity;
    JButton removeEntity;

    DefaultListModel entityModel;

    Object object;

    public PropertySidePanel() {
        super(new FlowLayout());
        model = new PropertySheetTableModel();
        pst = new PropertySheetTable(model);
        psp = new PropertySheetPanel(pst);

        addEntity = new JButton("+");
        removeEntity = new JButton("-");

        label1 = new JLabel("Entities");
		label1.setFont(new Font("Tahoma", Font.PLAIN, 14));

        entityModel = new DefaultListModel();
        entityPanel = new JPanel();
        entityList = new JList(entityModel);
        entityScroll = new JScrollPane(entityList);
        entityPanel.add(entityScroll);

        //entityPanel.setPreferredSize(new Dimension(200, 400));

        psp.setMode(PropertySheet.VIEW_AS_CATEGORIES);
        psp.setDescriptionVisible(true);
        psp.setSortingCategories(true);
        psp.setSortingProperties(true);
        psp.setRestoreToggleStates(true);

        psp.setPreferredSize(new Dimension(200, 300));
        
        this.add(psp);
        this.add(label1);
        this.add(entityPanel);
        this.add(addEntity);
        this.add(removeEntity);
        this.setPreferredSize(new Dimension(200, 800));
        this.setVisible(true);

    }

    public void setObject(Object object) {
        this.object = object;
        pst.setModel(PropertyGenerator.getProperty(object, model));
    }

}
